/**
 * Copyright 2011 Joe Choi, All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package tec.data.structure;

import java.util.Arrays;
import java.util.HashSet;

import tao.data.structure.Iterator;
import tao.data.structure.Set;

/**
 * @author Joe Choi
 */
public class ConcreteSet<V> implements Set<V> {	
	public ConcreteSet(V... elements) {
		data = new HashSet<V>();
		data.addAll(Arrays.asList(elements));
	}

	// Internal constructor for SetControl class
	ConcreteSet(java.util.Set<V> data) {
		if(data == null) throw new IllegalArgumentException();
		this.data = data;
	}
	
	@Override
	public int size() {
		return(data.size());
	}

	@Override
	public boolean contains(V e) {
		return(data.contains(e));
	}

	@Override
	public Iterator<V> iterate() {
		return(new IterateAdapter<V>(data.iterator()));
	}
	
	@Override
	public String toString() {
		String s = "{";
		for(V e : data) s += e + ", ";
		if(s.length() >= 3) s = s.substring(0, s.length() - 2);
		s += "}";
		return(s);
	}
	
	@Override
	public int hashCode()  {
		return(data.hashCode());
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null || (! (obj instanceof ConcreteSet<?>))) return(false);
		ConcreteSet<?> other = (ConcreteSet<?>) obj;
		return(this.data.equals(other.data));
	}
	
	private java.util.Set<V> data;
}